﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GBPVRX2.UiSupport;
using GBPVR.Public;
using System.Drawing;
using GBPVRLibrary.UtilityLibrary;

namespace GBPVRLibrary.ControlLibrary
{
    public class Rating:GuiElement
    {
        private GBPVRUiElement Element { get; set; }
        private GBPVRUiElement Background { get; set; }

        /// <summary>
        /// Gets or sets the value, from 0 to 1
        /// </summary>
        public double Value { get; set; }

        protected override void Render(System.Collections.ArrayList RenderList, ref bool RequiresMoreRendering)
        {
            if (Element == null)
                Element = new GBPVRUiElement("Rating", this.Location, SkinHelper.getNamedImage("Rating", new System.Collections.Hashtable()));
            if (Background == null)
                Background = new GBPVRUiElement("RatingBackground", this.Location, SkinHelper.getNamedImage("RatingBackground", new System.Collections.Hashtable()));
            RenderList.Add(Background);
            Element.SetRectangle(new RectangleF(this.Location.Location, new SizeF((float)(this.Location.Width * Value), this.Location.Height)));
            Element.textureBottomRight.X = (float)Value;
            Element.textureTopRight.X = (float)Value;
            RenderList.Add(Element);
        }

        public override void Dispose()
        {
            if (Element != null)
                PluginHelper.DisposeResource(Element);
            Element = null;
            if (Background != null)
                PluginHelper.DisposeResource(Background);
            Background = null;
        }
    }
}
